﻿@{
    ViewBag.Title = "addUserInfo";
    Layout = "~/Views/Shared/_ViewMenu.cshtml";
}
<script src="/Content/After/js/jquery.min.js"></script>
<script>
    function closeUserInfo() {
        location.href = "/UserInfo/Index";
    }
    function addUserInfo() {
        var AuthorId = new Array();

        $("[name='CkOne']:checked").each(function () {
            AuthorId.push($(this).val())
        })

        var UserName = $("#UserName").val();
        var UserPwd = $("#UserPwd").val();
        var UserChineseName = $("#UserChineseName").val();
        var UserSex = $("[name='sex']:checked").val();
        var UserPhone = $("#UserPhone").val();
        var UserEmail = $("#UserEmail").val();
        var DepartId = $("#DepartId").val();
        var UserSecrecy = $("[name='Secrecy']:checked").val();
        var UserState = $("[checked='checked']:checked").val();

        $.ajax({
            type: 'POST',
            url: '/UserInfo/FnaddUserInfodo',
            data: {
                UserName: UserName, UserPwd: UserPwd, UserChineseName: UserChineseName,
                UserSex: UserSex, UserPhone: UserPhone,
                UserEmail: UserEmail, DepartId: DepartId, AuthorId: AuthorId.toString(),
                UserSecrecy: UserSecrecy, UserState: UserState
            },
            dataType: 'Json',
            success: function (mes) {
                if (mes > 0) {
                    alert("已保存");
                    location.href = "/UserInfo/Index";
                }
                else {
                    alert("保存失败！");

                }
            }
        })
    }
</script>
@using ZX.HIS.Model;
@{
    List<ZX.HIS.Model.AuthorInfo> list = ViewBag.AuthorId;

}
<div id="urHere">DouPHP 管理中心<b>&gt;</b><strong>挂号信息</strong> </div>
<div style="width:100%">
    <div class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
        <h3><a href="/UserInfo/Index" class="actionBtn">返回</a>用户添加</h3>
        <div style="width:50%;float:left">
            <table width="100%" border="0" class="table table-bordered  tableBasic">
                <tbody>
                    <tr>
                        <td width="80" align="right">登录账号</td>
                        <td>
                            <input id="UserName" type="text" class="inpMain" name="UserName" size="40" />
                        </td>
                    </tr>
                    <tr>
                        <td align="right">密码:</td>
                        <td>
                            <input id="UserPwd" type="text" class="inpMain" name="UserPwd" size="40" />
                        </td>
                    </tr>
                    <tr>
                        <td align="right">中文名:</td>
                        <td>
                            <input id="UserChineseName" type="text" class="inpMain" name="UserChineseName" size="40" />
                        </td>
                    </tr>
                    <tr>
                        <td align="right">性别:</td>
                        <td>
                            <input id="UserSex" type="radio" value="1" name="sex" checked="checked" />男
                            <input id="UserSex" type="radio" value="0" name="sex" />女
                        </td>
                    </tr>
                    <tr>
                        <td align="right">手机号:</td>
                        <td>
                            <input id="UserPhone" type="text" class="inpMain" name="UserPhone" size="40" />
                        </td>
                    </tr>
                    <tr>
                        <td align="right">邮箱:</td>
                        <td>
                            <input id="UserEmail" type="email" class="inpMain" name="UserEmail" size="40" />
                    </tr>
                    <tr>
                        <td align="right">科室:</td>
                        <td>@Html.DropDownList("DepartId")</td>
                    </tr>

                    <tr>
                        <td align="right">保密设置:</td>
                        <td>
                            查看诊所全部患者及处方信息：
                            <input id="UserSecrecy" type="radio" value="1" name="Secrecy" />是
                            <input id="UserSecrecy" type="radio" value="0" name="Secrecy" checked="checked" />否
                        </td>
                    </tr>
                    <tr>
                        <td align="right">状态:</td>
                        <td>
                            <input id="UserState" type="radio" value="1" name="state" checked="checked" />启用
                            <input id="UserState" type="radio" value="0" name="state" />禁用
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <input id="Button1" type="button" value="保存" class="btn" onclick="addUserInfo()" />
                            <input id="Button1" type="button" value="取消" class="btn" onclick="closeUserInfo()" />
                        </td>
                    </tr>
                    </tbody>
            </table>
        </div>
        <div style="width:40%;float:right">
            <input id="CkAll" type="checkbox" name="CkAll" />全选
            <ul>
                @foreach (var i in list)
                {
                    if (i.AuthorParentId == 0)
                    {
                        <li class="list-group-item ">
                            <span name="ClickLi" class="glyphicon glyphicon-chevron-right"></span>
                            <input type="checkbox" ckparent="@i.AuthorId" name="CkOne" ckchild="@i.AuthorParentId" value="@i.AuthorId" onchange="ChangeCheck(@i.AuthorParentId,@i.AuthorId,this.checked)" />
                            @i.AuthorName
                            <ul class="hide">
                                @foreach (var p in list)
                                {

                                    if (p.AuthorParentId == i.AuthorId)
                                    {
                                        <li class="list-group-item ">
                                            <span name="ClickLi" class="glyphicon glyphicon-chevron-right"></span>
                                            <input type="checkbox" ckparent="@p.AuthorId" name="CkOne" ckchild="@p.AuthorParentId" value="@p.AuthorId" onchange="ChangeCheck(@p.AuthorParentId,@p.AuthorId,this.checked)" />
                                            @p.AuthorName
                                        </li>
                                    }
                                }
                            </ul>
                        </li>
                    }
                }
            </ul>
        </div>
        <div class="clear"></div>
    </div>
    <script>
        function ChangeCheck(ParentId, ChildId, IsCheck) {
            $("[ckparent=" + ParentId + "]").prop("checked", IsCheck)
            $("[ckchild=" + ChildId + "]").prop("checked", IsCheck);
        }
        $(function () {
            $("span[name=ClickLi]").click(function () {
                var ThisUl = $(this).parent().find("ul");
                if ($(ThisUl[0]).hasClass("hide")) {
                    $(ThisUl[0]).stop().fadeIn(500).removeClass("hide");
                    $(this).removeClass("glyphicon-chevron-right").addClass("glyphicon-chevron-down")
                } else {
                    $(ThisUl[0]).addClass("hide");
                    $(this).addClass("glyphicon-chevron-right").removeClass("glyphicon-chevron-down");
                }
            })
            $("#CkAll").click(function () {
                $(":input[name=CkOne]").prop("checked", this.checked);
            })
        })
    </script>
</div>